package com.x.crm.dao;

import com.x.crm.model.Follow;
import com.x.framework.dao.BaseDao;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class FollowDao extends BaseDao {
    private static final String baseQueryStr = "SELECT * FROM CRM_FOLLOW WHERE INTENTION_ID = ?";
    public List<Follow> selectByIntentionId(Follow followWhere) throws Exception {
        List<Object> params = new ArrayList<Object>();
        params.add(followWhere.getIntentionId());
        return this.queryForList(baseQueryStr.toString(), Follow.class, params);
    }

    private static final String baseQueryStr_selectFollowList = "SELECT * FROM CRM_FOLLOW F WHERE FOLLOW_ID > 0 ";
    public List<Follow> selectFollowList(Follow follow) throws Exception {
        StringBuilder sql = new StringBuilder(baseQueryStr_selectFollowList);
        List<Object> params = new ArrayList<Object>();
        if(this.isNotNull(follow.getAppointmentTime())){
            sql.append(" AND F.APPOINTMENT_TIME = ? ");
            params.add(follow.getAppointmentTime());
        }
        if(this.isNotNull((follow.getFixturePrice()))){
            sql.append(" AND F.FIXTURE_PRICE = ? ");
            params.add(follow.getFixturePrice());
        }
        if(this.isString(follow.getFixtureVIN())){
            sql.append(" AND F.FIXTURE_VIN = ? ");
            params.add(follow.getFixtureVIN());
        }
        if(this.isString(follow.getFollowerId())){
            sql.append(" AND F.FOLLOWER_ID = ? ");
            params.add(follow.getFollowerId());
        }
        if(this.isString(follow.getFollowId())){
            sql.append(" AND F.FOLLOW_ID = ? ");
            params.add(follow.getFollowId());
        }
        if(this.isString(follow.getFollowResult())){
            sql.append(" AND F.FOLLOW_RESULT = ? ");
            params.add(follow.getFollowResult());
        }
        if(this.isString(follow.getIntentionId())){
            sql.append(" AND F.INTENTION_ID = ? ");
            params.add(follow.getIntentionId());
        }
        if(this.isString(follow.getCustomerShopId())){
            sql.append(" AND F.CUSTOMER_SHOP_ID = ? ");
            params.add(follow.getCustomerShopId());
        }
        sql.append(" ORDER BY F.CREATE_TIME DESC ");
        return this.queryForList(sql.toString(), Follow.class, params);
    }
}